1 00:00:00,510 --> 00:00:01,470 Welcome back. 2 00:00:01,470 --> 00:00:07,710 In this lecture we're going to be learning about a fundamental feature in Roblox studio called Ray casting. 3 00:00:07,740 --> 00:00:15,840 Ray casting is this idea of shooting an invisible ray in a defined direction with a defined distance, 4 00:00:15,840 --> 00:00:20,490 and checking to see if that ray hit any 3D object in our workspace. 5 00:00:20,790 --> 00:00:26,820 To be able to perform a raycast, we first need an origin point and a direction that defines where we 6 00:00:26,820 --> 00:00:30,420 want to shoot a ray from with respect to that origin point. 7 00:00:31,130 --> 00:00:36,380 A cool way for us to demonstrate Raycasting would be creating a simple tool, and every time the player 8 00:00:36,380 --> 00:00:42,110 clicks the tool, we're going to fire a ray pointing towards wherever that tool is looking, and then 9 00:00:42,110 --> 00:00:45,980 we'll check to see if that ray hits any object in our workspace. 10 00:00:45,980 --> 00:00:49,310 So we're going to create a new tool in the starter pack. 11 00:00:50,040 --> 00:00:53,430 And I'm just going to call this tool Raycast tool. 12 00:00:54,550 --> 00:00:59,140 And then for the handle for this tool, I'll just create a new part inside of my tool. 13 00:00:59,140 --> 00:01:02,920 I'll call it handle and I'm going to make it a little bit smaller. 14 00:01:02,920 --> 00:01:09,970 So I'll just uh, I'll just have the dimensions be a cube of 0.5 by 0.5 by 0.5 studs, and then we'll 15 00:01:09,970 --> 00:01:12,580 make sure can collide is turned off for this handle. 16 00:01:12,580 --> 00:01:14,440 And we'll make sure it's unanchored as well. 17 00:01:14,830 --> 00:01:19,510 And then inside of here we can go ahead and create a server script to listen to the events for this 18 00:01:19,510 --> 00:01:20,140 tool. 19 00:01:20,970 --> 00:01:22,980 So I'll make a reference to my tool. 20 00:01:22,980 --> 00:01:24,240 Create a variable called tool. 21 00:01:24,240 --> 00:01:26,550 And that's just equal to script dot parent. 22 00:01:26,550 --> 00:01:31,170 And then I'll also make a reference to my handle and let's say child of my tool. 23 00:01:32,090 --> 00:01:38,870 And then what we could do is when the tool is activated by a player, we can go ahead and shoot a ray 24 00:01:38,990 --> 00:01:43,190 in the direction of wherever our handle is facing in our tool. 25 00:01:43,890 --> 00:01:45,120 To fire a ray. 26 00:01:45,120 --> 00:01:51,000 In our game, we use a function underneath the workspace of raycast and as you can see it says this 27 00:01:51,000 --> 00:01:57,120 function takes an origin point, a direction as well as some optional raycast parameters, and it says 28 00:01:57,120 --> 00:02:01,440 casts a ray using an origin direction and an optional raycast parameters. 29 00:02:01,440 --> 00:02:06,960 Then returns a raycast result if an eligible object or terrain intersects the ray. 30 00:02:07,590 --> 00:02:13,260 Here in the Roblox documentation, we can see that a raycast result is a custom data type, and it says. 31 00:02:13,260 --> 00:02:18,300 This data type stores the result of successful Raycasting operation performed by World Route, which 32 00:02:18,300 --> 00:02:21,090 would be the workspace and the raycast function. 33 00:02:21,090 --> 00:02:26,040 And inside of this data type it stores some properties such as the distance it says, the distance between 34 00:02:26,040 --> 00:02:30,570 the ray origin and the intersection point, the instance that was hit. 35 00:02:30,570 --> 00:02:34,110 So that would be the base part or the terrain that the ray intersected. 36 00:02:34,110 --> 00:02:36,870 There would be the material at the intersection point. 37 00:02:36,870 --> 00:02:43,680 It gives us the position where this ray hit an object, as well as the normal and the normal vector 38 00:02:43,680 --> 00:02:45,120 of the intersected face. 39 00:02:45,120 --> 00:02:51,750 And the normal vector is basically just what direction is forward for whatever part's face it hit. 40 00:02:51,750 --> 00:02:59,040 So if it hit one side of a part, then the normal or the direction that that face is looking towards 41 00:02:59,040 --> 00:03:01,950 would be this normal property right here. 42 00:03:02,760 --> 00:03:07,770 We can also go ahead and take a look at the raycast parameter data type and it says the raycast parameter. 43 00:03:07,770 --> 00:03:12,960 Data type stores parameters for the raycast function and it has some properties down here. 44 00:03:12,960 --> 00:03:19,290 This is an array called Filter Descendants instances, and we would pass a table or an array of objects 45 00:03:19,290 --> 00:03:25,200 whose descendants are used in filtering raycast candidates, and we choose this by setting the filter 46 00:03:25,200 --> 00:03:28,200 type with an enum raycast filter type. 47 00:03:28,200 --> 00:03:35,640 So we would either include or exclude these certain objects from the raycast operation if we include 48 00:03:35,640 --> 00:03:36,060 them. 49 00:03:36,060 --> 00:03:41,700 That means this raycast is going to ignore every single object in our game, except for the objects 50 00:03:41,700 --> 00:03:44,550 within our filter descendants instances array. 51 00:03:44,550 --> 00:03:51,090 And if we set the filter type to exclude, then the raycast is going to include every object in our 52 00:03:51,090 --> 00:03:54,930 game except for the objects that are inside of this array. 53 00:03:55,200 --> 00:03:57,750 We also have some additional properties here, such as. 54 00:03:57,750 --> 00:03:59,790 If we would like the ray to ignore water. 55 00:03:59,790 --> 00:04:04,830 We can also set a collision group that we would like the raycast to include or exclude. 56 00:04:04,830 --> 00:04:10,020 There's another property here called respect can Collide and it says determines whether the raycast 57 00:04:10,020 --> 00:04:14,880 operation considers a parts can collide property over its can query value. 58 00:04:14,880 --> 00:04:18,840 And every single part in your game has this property called can query. 59 00:04:18,840 --> 00:04:26,520 And this property allows you to basically select which parts in your game are included or excluded in 60 00:04:26,520 --> 00:04:27,990 raycast operations. 61 00:04:27,990 --> 00:04:33,900 Any parts in your game that have the can query property set to false will not be included in any raycast. 62 00:04:33,900 --> 00:04:36,390 And then this last one here is called Brute Force. 63 00:04:36,390 --> 00:04:42,630 All slow and it says when enabled, the query will ignore all part collision properties and perform 64 00:04:42,630 --> 00:04:45,090 a brute force check on every single part. 65 00:04:46,320 --> 00:04:47,640 Back in studio. 66 00:04:47,640 --> 00:04:53,670 Whenever our player activates this tool, we want to go ahead and shoot a ray from an origin point, 67 00:04:53,670 --> 00:04:59,550 which would be the position of our handle in a direction which would be wherever our handle is facing. 68 00:04:59,970 --> 00:05:02,100 So we can call our raycast function. 69 00:05:02,100 --> 00:05:06,540 And that means we need to pass the origin direction and optional raycast parameters. 70 00:05:06,540 --> 00:05:09,060 So let's go ahead and create two variables. 71 00:05:09,060 --> 00:05:14,880 One variable is going to be my origin, while the other variable is going to be my direction. 72 00:05:15,450 --> 00:05:18,210 So for the origin this one's going to be very simple. 73 00:05:18,210 --> 00:05:21,870 The origin is going to be my handles position in the workspace. 74 00:05:21,870 --> 00:05:23,970 So we just get handle dot position. 75 00:05:23,970 --> 00:05:26,520 This is where we would like the ray to start at. 76 00:05:26,520 --> 00:05:31,560 And then the direction is going to be whichever way our handle is facing. 77 00:05:31,560 --> 00:05:37,080 And to get the look vector of our handle we can reference our handle keyframe. 78 00:05:37,080 --> 00:05:40,110 And our keyframe stores the look vector property. 79 00:05:40,110 --> 00:05:45,330 And that returns the forward direction component of the keyframe object's orientation. 80 00:05:45,330 --> 00:05:49,680 So this will basically tell us where our part is looking as an example. 81 00:05:50,470 --> 00:05:55,660 If we take a look at this part right here, and we right click our part and we press Show Orientation 82 00:05:55,660 --> 00:06:03,040 indicator here, it shows us the look vector for this part, which is on this front facing side of our 83 00:06:03,040 --> 00:06:03,490 part. 84 00:06:03,490 --> 00:06:07,360 And that is the direction or the look vector for this part. 85 00:06:08,330 --> 00:06:13,550 Now that we have our origin and our direction, we can go ahead and pass the origin and then we can 86 00:06:13,550 --> 00:06:15,440 also pass the direction. 87 00:06:15,470 --> 00:06:20,330 Now this direction also needs to include a length or a magnitude. 88 00:06:20,330 --> 00:06:26,870 And as you can see it says note that the length of this vector matters as part trains further away than 89 00:06:26,870 --> 00:06:28,730 its length will not be tested. 90 00:06:28,730 --> 00:06:35,120 So this is where you would multiply this vector by a value, which would indicate how long you would 91 00:06:35,120 --> 00:06:37,070 like this direction to be. 92 00:06:37,070 --> 00:06:42,230 For example, if I multiplied this direction by the value of ten, then my direction is going to be 93 00:06:42,230 --> 00:06:43,940 ten studs in length. 94 00:06:43,940 --> 00:06:49,610 So this is going to fire a ray up to ten studs away from me, and then it's going to stop and ignore 95 00:06:49,610 --> 00:06:51,260 anything else further away. 96 00:06:51,260 --> 00:06:55,370 If I want it to shoot farther than that, I could enter a value like 500. 97 00:06:55,370 --> 00:07:02,450 And now my direction is going to basically fire a ray 500 studs away from me, and this ray will stop 98 00:07:02,450 --> 00:07:05,420 once it hits a part in our workspace. 99 00:07:05,930 --> 00:07:09,290 So for this demonstration, we'll just put it at 100 studs. 100 00:07:09,530 --> 00:07:13,400 And of course this function is going to return to us a raycast result. 101 00:07:13,400 --> 00:07:15,740 So we'll create a variable and we'll just call it result. 102 00:07:16,620 --> 00:07:19,890 Now we're also going to go ahead and take a look at raycast parameters. 103 00:07:19,890 --> 00:07:25,080 So outside of my activated event I'm going to create a variable called params. 104 00:07:25,140 --> 00:07:27,510 And that's going to be equal to a new raycast parameter. 105 00:07:27,510 --> 00:07:29,580 So we refer to raycast params. 106 00:07:29,580 --> 00:07:32,550 And then to create one we use the new constructor. 107 00:07:32,880 --> 00:07:38,040 And then from here we have access to all of those different properties inside of this data type, such 108 00:07:38,040 --> 00:07:42,810 as filter descendant instances, the filter type and some other settings as well. 109 00:07:43,320 --> 00:07:51,390 If we would like to exclude some different items from our raycast and we can set the filter type equal 110 00:07:51,390 --> 00:07:55,230 to the enum dot raycast filter type dot exclude. 111 00:07:55,230 --> 00:07:59,040 This used to be blacklist, but for some reason they deprecated it. 112 00:07:59,040 --> 00:08:01,740 As you can see it is um. 113 00:08:02,480 --> 00:08:03,680 Has a strike through through it. 114 00:08:03,680 --> 00:08:04,910 So that means it's deprecated. 115 00:08:04,910 --> 00:08:10,430 I don't know why they deprecated Blacklist and Whitelist and replaced it with exclude and include, 116 00:08:10,430 --> 00:08:11,840 but it's whatever. 117 00:08:11,840 --> 00:08:15,200 So we use exclude now instead of blacklist. 118 00:08:15,590 --> 00:08:22,070 Then every time we activate the tool, some things that we want to go ahead and ignore from this raycast 119 00:08:22,070 --> 00:08:24,830 would be for example, our player's character. 120 00:08:24,830 --> 00:08:30,080 We don't want to intersect with anything on our player's character, and we certainly don't want to 121 00:08:30,080 --> 00:08:36,290 intersect with the handle that the ray is going to be firing from, because that'd be kind of stupid. 122 00:08:36,290 --> 00:08:43,460 So what we can do is we can go ahead and update the parameters dot filter, descendent instances equal 123 00:08:43,460 --> 00:08:44,660 to a new table. 124 00:08:44,660 --> 00:08:48,650 And this table is going to contain the parent of our tool. 125 00:08:48,650 --> 00:08:53,840 And since this tool can only be activated when it's equipped, that means the parent of our tool is 126 00:08:53,840 --> 00:08:55,880 going to be a player's character model. 127 00:08:55,880 --> 00:08:58,610 And that character model includes this tool. 128 00:08:58,610 --> 00:09:05,450 So this tool is going to be exempt from our raycast as well as any descendants or 3D object descendants 129 00:09:05,450 --> 00:09:06,950 of our player's character. 130 00:09:07,660 --> 00:09:13,210 Now we can go ahead and pass our raycast parameters to our raycast function to be included in our raycast 131 00:09:13,210 --> 00:09:14,050 operation. 132 00:09:15,580 --> 00:09:20,620 Now this is going to fire a ray inside of our workspace, and it's going to check to see if it hits 133 00:09:20,620 --> 00:09:21,310 anything. 134 00:09:21,310 --> 00:09:23,740 And that's going to be returned in this raycast result. 135 00:09:23,740 --> 00:09:28,120 So we can go ahead and check if this function actually returns something. 136 00:09:28,120 --> 00:09:32,920 Because if this raycast didn't hit anything, then the function is going to return nil. 137 00:09:33,220 --> 00:09:38,260 So we can check to see if we hit something by checking to see if there's a value stored in result. 138 00:09:39,170 --> 00:09:42,260 And if there is, then we can go ahead and print that. 139 00:09:42,260 --> 00:09:43,820 We hit an instance. 140 00:09:43,820 --> 00:09:49,160 And this result of course stores some information, for example, the instance that we hit. 141 00:09:49,160 --> 00:09:52,130 So we can get the instance and then the name of the instance. 142 00:09:52,130 --> 00:09:54,980 So we can print that we hit this particular instance. 143 00:09:54,980 --> 00:09:58,310 And then we can also print out what position we hit this instance. 144 00:09:58,310 --> 00:10:00,020 So I'll say at position. 145 00:10:00,020 --> 00:10:03,260 And then we can pass the results dot position. 146 00:10:04,250 --> 00:10:09,590 Otherwise, if there is no result, that means our raycast did not find any 3D objects in our workspace 147 00:10:09,590 --> 00:10:14,030 to hit, so we can print something like the ray hit nothing. 148 00:10:16,290 --> 00:10:19,770 So now let's go ahead and playtest our game and see what happens. 149 00:10:21,040 --> 00:10:23,560 So here is my raycast tool and my part. 150 00:10:23,560 --> 00:10:29,200 And this should shoot a ray out from this face of my part in that direction. 151 00:10:29,200 --> 00:10:30,250 100 studs. 152 00:10:30,250 --> 00:10:35,140 If it hits anything then it'll print what it hit, otherwise it should print nothing. 153 00:10:35,170 --> 00:10:39,010 So if I turn and face this part and then I were to click. 154 00:10:39,280 --> 00:10:45,190 As you can see, it says we hit an instance part at position, and then it gives us the exact position 155 00:10:45,190 --> 00:10:47,650 where the ray intersected with the part. 156 00:10:47,680 --> 00:10:51,040 We can also click over here or click here. 157 00:10:51,040 --> 00:10:56,200 But if we face away from our part and then we shoot, as you can see, the ray hit nothing because there's 158 00:10:56,200 --> 00:10:58,870 nothing in front of us for the ray to intersect. 159 00:10:59,750 --> 00:11:05,750 Now we can also go ahead and visualize this raycast by creating a part, and then positioning that part 160 00:11:05,750 --> 00:11:13,520 between our origin point and the hit point, and then increasing the length of our part to represent 161 00:11:13,520 --> 00:11:16,310 the total distance of the raycast. 162 00:11:16,310 --> 00:11:18,080 So let's go ahead and do that. 163 00:11:18,080 --> 00:11:23,780 If we get a result from our raycast, then what we can do is we can create a new part. 164 00:11:26,160 --> 00:11:33,150 And the size of this part is going to be equal to a new vector three and for the x size, we need it 165 00:11:33,150 --> 00:11:34,890 to be 0.05. 166 00:11:34,890 --> 00:11:38,220 And for the y size we also need it to be 0.05. 167 00:11:38,220 --> 00:11:44,700 And the z is going to be the length or the distance between the origin point and the hit point from 168 00:11:44,700 --> 00:11:46,530 our result data type here. 169 00:11:46,770 --> 00:11:50,940 So this is going to be equal to the result dot distance. 170 00:11:51,880 --> 00:11:58,330 And the reason we have to do it on the Z axis is that if we take a look and we create a new part here. 171 00:11:59,330 --> 00:12:02,060 And we were to show the orientation indicator. 172 00:12:02,060 --> 00:12:04,160 So this is the front of my part. 173 00:12:04,160 --> 00:12:10,520 And if we were to resize this part, as you can see, the area we need to resize is the z axis when 174 00:12:10,520 --> 00:12:12,170 this part faces an object. 175 00:12:12,170 --> 00:12:19,820 And that's because we need to set the keyframe of this part to be facing towards wherever we hit, and 176 00:12:19,820 --> 00:12:21,980 that way it's accurate and it looks correct. 177 00:12:21,980 --> 00:12:29,270 So if we were to set the size to be 0.05 and 0.05 and then like ten, then this is what our array is 178 00:12:29,270 --> 00:12:30,320 going to look at. 179 00:12:30,320 --> 00:12:35,180 And this part is basically going to visualize where our ray hit in the workspace. 180 00:12:35,180 --> 00:12:40,580 It's going to look towards where we hit and it's going to orient itself correctly. 181 00:12:40,580 --> 00:12:47,360 We can imagine this end as the origin point and this end as the point of where we intersected a part. 182 00:12:47,390 --> 00:12:49,460 This is what our array is going to look like. 183 00:12:50,640 --> 00:12:53,280 Once we set the size, we can go ahead and change the color. 184 00:12:53,280 --> 00:12:55,080 I'll just make it completely white. 185 00:12:55,080 --> 00:12:58,470 So we'll do from RGB and we'll create. 186 00:12:58,470 --> 00:12:59,130 It's already white. 187 00:12:59,130 --> 00:13:00,240 So we'll just do that. 188 00:13:00,660 --> 00:13:02,490 We'll make sure the part is anchored. 189 00:13:02,490 --> 00:13:05,310 And we'll also make sure that can collide is false. 190 00:13:05,310 --> 00:13:06,420 So we don't hit it. 191 00:13:06,840 --> 00:13:10,890 And now we need to go ahead and update the keyframe of our part. 192 00:13:10,890 --> 00:13:12,540 And this is going to be simple. 193 00:13:12,540 --> 00:13:15,780 All we need to do is use the keyframe dot lookup function. 194 00:13:15,780 --> 00:13:21,360 And remember this returns a keyframe with a position of the first vector and an orientation pointed 195 00:13:21,360 --> 00:13:22,440 towards the second. 196 00:13:22,440 --> 00:13:28,530 So we're basically positioning this part to be at the origin, and we want it to look at wherever we 197 00:13:28,560 --> 00:13:30,960 hit, which would be the result dot position. 198 00:13:30,960 --> 00:13:36,180 So now our part is going to be looking towards this position from the origin point. 199 00:13:36,850 --> 00:13:42,820 Now, since the pivot of our part is directly in the center, for example, that is our central pivot 200 00:13:42,820 --> 00:13:43,780 point of the part. 201 00:13:43,780 --> 00:13:46,030 It's not at the end or over here. 202 00:13:46,030 --> 00:13:51,370 That means we need to account for the fact that the pivot is in the center of our part. 203 00:13:51,400 --> 00:13:56,920 So we need to move this part by half of the distance. 204 00:13:56,920 --> 00:14:03,250 So that way it's perfectly positioned between the origin point and the point at where we hit. 205 00:14:03,940 --> 00:14:07,630 To visualize this, you can basically think of this black dot right here as our player. 206 00:14:07,630 --> 00:14:10,060 And then this red dot is our origin point. 207 00:14:10,060 --> 00:14:12,070 And this other red dot is where we hit. 208 00:14:12,070 --> 00:14:13,630 And you can imagine this as another part. 209 00:14:13,630 --> 00:14:16,780 So the player fired a ray towards this direction. 210 00:14:16,780 --> 00:14:17,890 And we hit right here. 211 00:14:17,890 --> 00:14:22,360 And we want to get the position between these two points the half way mark. 212 00:14:22,360 --> 00:14:28,780 So that way we can accurately set the keyframe of our part to be perfectly between these two parts. 213 00:14:29,020 --> 00:14:34,630 If we didn't account for this offset, then our part would instead look something like this, where 214 00:14:34,630 --> 00:14:40,360 the central point of our part would be next to our origin point, it would look incorrect, so we need 215 00:14:40,360 --> 00:14:48,400 to offset it by whatever half the distance is between our origin point and our hit point. 216 00:14:50,120 --> 00:14:51,770 And that's very easy to do as well. 217 00:14:51,770 --> 00:14:57,140 All we need to do is add a new keyframe and remember to add a keyframe to another keyframe. 218 00:14:57,140 --> 00:15:01,130 We have to use the multiplication symbol and not the addition symbol. 219 00:15:01,130 --> 00:15:07,010 The addition symbol is when you offset it using vectors, and then the multiplication symbol is when 220 00:15:07,010 --> 00:15:09,170 we offset it with another keyframe. 221 00:15:09,170 --> 00:15:11,600 So we'll create another new keyframe here. 222 00:15:11,600 --> 00:15:18,530 We don't need to offset it on the x axis or the z axis, but we need to offset it on the z axis, because 223 00:15:18,530 --> 00:15:21,230 that's the direction where the look vector is. 224 00:15:21,230 --> 00:15:28,310 And that z offset, remember, is going to be half the distance of result dot distance. 225 00:15:28,310 --> 00:15:32,720 So we'll just pass result dot distance and then divide it by two. 226 00:15:32,720 --> 00:15:37,760 And then in order to make sure that this offsets in the correct direction we actually need to negate 227 00:15:37,760 --> 00:15:38,750 this value. 228 00:15:39,080 --> 00:15:42,320 So basically shifting the position of this part. 229 00:15:42,890 --> 00:15:49,940 From the origin point to the point between the origin and the position of where we hit. 230 00:15:50,600 --> 00:15:55,820 And then once we do that, we can finally set the parent of our part equal to the workspace so we can 231 00:15:55,820 --> 00:15:57,260 actually see it in our game. 232 00:15:57,560 --> 00:15:59,390 So now if we go and play test. 233 00:16:00,500 --> 00:16:02,480 If I were to look away and I clicked. 234 00:16:02,480 --> 00:16:04,160 As you can see, the ray hit nothing. 235 00:16:04,160 --> 00:16:07,220 But if I turn around and look at my part and then I click. 236 00:16:07,520 --> 00:16:12,020 As you can see now we have visualized this raycast with this custom part right here. 237 00:16:12,020 --> 00:16:18,200 This was my origin point and the ray fired in this direction and kept going until it hit my part. 238 00:16:18,200 --> 00:16:21,560 And that's where this part ends, right? 239 00:16:22,190 --> 00:16:27,680 So that is the total distance between the origin point and the point at which we hit. 240 00:16:27,680 --> 00:16:33,350 And of course, we can keep shooting these rays out and keep firing them and keep visualizing them. 241 00:16:33,350 --> 00:16:39,680 And those are all of the ray casts that are being shot out from my origin point, and hitting this part 242 00:16:39,680 --> 00:16:40,340 right here. 243 00:16:40,340 --> 00:16:44,180 And of course, I can't hit anything that is not in front of me. 244 00:16:44,180 --> 00:16:49,130 But if I walk, you can see that the origin point is moving up and down. 245 00:16:49,130 --> 00:16:54,710 And then if I click, as you can see, the look vector of this part is pointed downwards as I walk. 246 00:16:54,710 --> 00:16:56,660 So we're hitting the base plate now. 247 00:16:58,500 --> 00:17:02,790 One more thing before I let you go, let's go ahead and take a look at the Cam query property. 248 00:17:02,790 --> 00:17:03,750 For parts. 249 00:17:03,960 --> 00:17:08,970 To access the can query property, we have to go down to the collision section and the properties panel 250 00:17:08,970 --> 00:17:09,720 for this part. 251 00:17:09,720 --> 00:17:14,760 And in order to see the can query property we have to go ahead and disable can collide. 252 00:17:14,760 --> 00:17:18,450 Once we disable can collide then the can query property shows up. 253 00:17:18,450 --> 00:17:23,670 And this will determine whether or not this part is going to be involved in any spatial queries in the 254 00:17:23,670 --> 00:17:25,590 game, including Raycasts. 255 00:17:25,590 --> 00:17:31,470 So if I disable this property and then we go and playtest our game, now when I go and click my tool 256 00:17:31,470 --> 00:17:35,280 to try and fire a ray at this part, it's not going to intersect anything. 257 00:17:35,280 --> 00:17:37,320 So if I hold out my tool and then I click. 258 00:17:37,320 --> 00:17:41,970 As you can see, this part is now being excluded from that raycast operation. 259 00:17:41,970 --> 00:17:44,580 And it's telling us that the ray hit nothing. 260 00:17:44,580 --> 00:17:49,380 I can keep clicking and keep clicking, and no matter what, the ray is going to permanently ignore 261 00:17:49,380 --> 00:17:50,310 this part. 262 00:17:51,970 --> 00:17:54,760 So this is how we can visualize Raycasts. 263 00:17:54,760 --> 00:18:01,420 And this is also how we can use Raycasts to detect when we hit parts or 3D objects in our game. 264 00:18:02,930 --> 00:18:04,790 That's all for me for this lecture. 265 00:18:04,790 --> 00:18:07,610 I hope you enjoyed and I'll see you in the next one.